#!/bin/bash
######################################################################
# this script is used for extracting tomcat accesslog parameters into 
# sepcificed csv file
######################################################################

inputfile=$1
outputfile=$2

if [ "$inputfile" == "" ] || [ "$outputfile" == "" ]
then
  echo 'usage: command <inputfile> <outputfile>'
  exit 0
fi
echo "begin to extract $inputfile into $outputfile..."

awk -F'?' '{print $2}' $inputfile | awk -F' HTTP' '{print $1}' | awk '{split($0,arr,"&"); print(substr(arr[1],index(arr[1],"=")+1) "," substr(arr[2],index(arr[2],"=")+1) "," substr(arr[3],index(arr[3],"=")+1) "," substr(arr[6],index(arr[6],"=")+1))}' | grep -v ',,,' > $outputfile

echo 'end of extracting...'

